package com.sleep.blog.controller;

import com.sleep.blog.service.CommentService;
import com.sleep.blog.vo.Result;
import com.sleep.blog.vo.params.CommentParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Sleep-6000
 * @date 2021/9/29
 */
@RestController
@RequestMapping("comments")
public class CommentsController {

    @Autowired
    private CommentService commentService;

    /**
     * 根据 文章id 查询评论列表
     * @param id 文章id
     * @return 评论列表
     */
    @GetMapping("article/{id}")
    public Result findCommentsById(@PathVariable("id") Long id) {
        return commentService.findCommentsById(id);
    }

    /**
     * 写评论
     * @param commentParam commentParam
     * @return comment
     */
    @PostMapping("create/change")
    public Result comment(@RequestBody CommentParam commentParam) {
        return commentService.comment(commentParam);
    }
}
